package com.quanquan.user.repository;

import com.quanquan.user.entity.UserGroupRelationShip;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 功能描述:分组管理 （新建，删除，更新）
 *
 * @ClassName: UserGroupRepository
 * @Author: xiaoqianh丶
 * @Date: 2019-03-19 14:59
 * @Version: V1.0
 */

public interface UserGroupRelationshipRepository extends JpaRepository<UserGroupRelationShip, String>, JpaSpecificationExecutor<UserGroupRelationShip> {


    /**
     * 根据分组id查询所有分组成员
     * @param groupId
     * @param num
     * @return
     */
    public List<UserGroupRelationShip> findByGroupIdAndRemove(String groupId, Integer num);


    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value="update oo_user_group_relation_ship set status_remove= 1 where group_id =?1" ,nativeQuery=true)
    public void removeAllRelationshipByGroupId(String groupId);




    @Modifying
    @Transactional
    @Query(value="delete from oo_user_group_relation_ship  where group_id=?1",nativeQuery=true)
    public void removeAllRelationshipId(String groupId);

}
